package com.test.pdproject.service;

import com.test.pdproject.constant.Page;
import com.test.pdproject.constant.PageData;
import com.test.pdproject.dao.DaoSupport;
import com.test.pdproject.datasources.DataSourceNames;
import com.test.pdproject.datasources.annotation.DataSource;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("bankService")
public class BankService {

	@Resource(name = "daoSupport")
	private DaoSupport dao;

	// ======================================================================================

	/*
	 * 通过id获取数据
	 */
	public PageData findById(PageData pd) throws Exception {
		return (PageData) dao.findForObject("BankMapper.findById", pd);
	}

	/**
	 *
	 * @param pd
	 * @throws Exception
	 */
	public PageData findByName(PageData pd) throws Exception {
		return (PageData) dao.findForObject("BankMapper.findByName", pd);
	}
	/*
	 * 保存
	 */
	public void save(PageData pd) throws Exception {
		dao.save("BankMapper.save", pd);
	}

	/*
	 * 修改
	 */
	public void edit(PageData pd) throws Exception {
		dao.update("BankMapper.edit", pd);
	}

	/*
	 * 删除
	 */
	public void delete(PageData pd) throws Exception {
		dao.delete("BankMapper.delete", pd);
	}

	/*
	 * 列表(分页)
	 */
	@SuppressWarnings("unchecked")
	@DataSource(name = DataSourceNames.FIRST)
	public List<PageData> searchlistPage(Page page) throws Exception {
		return (List<PageData>) dao.findForList("BankMapper.searchlistPage", page);
	}
	/*
	 * 列表(分页)
	 */
	@SuppressWarnings("unchecked")
	@DataSource(name = DataSourceNames.SECOND)
	public List<PageData> searchlist2Page(Page page) throws Exception {
		return (List<PageData>) dao.findForList("BankMapper.searchlistPage", page);
	}

	/*
	 * 列表
	 */
	@SuppressWarnings("unchecked")
	public List<PageData> searchlist(Page page) throws Exception {
		return (List<PageData>) dao.findForList("BankMapper.searchlist", page);
	}
}
